package restructure.chapter06;

import java.util.Date;

/**
 * 6.7 移除对参数的赋值
 */
public class RemoveAssignmentsToParameters {


    int discount(int inputValue, int quantity, int yearToDate) {
        if (inputValue > 50) inputValue -= 2;
        if (quantity > 100) inputValue -= 1;
        if (yearToDate > 10000) inputValue -= 4;
        return inputValue;
    }

    /**
     * 不对参数赋值，还可以为参数加上关键词final，从而强制它遵循“不对参数赋值”
     */
    int discount_(final int inputValue, int quantity, int yearToDate) {
        int result = inputValue;
        if (inputValue > 50) result -= 2;
        if (quantity > 100) result -= 1;
        if (yearToDate > 10000) result -= 4;
        return result;
    }

    public static void main(String[] args) {
        Date d1 = new Date("1 Apr 98");
    }




}
